package com.polaris.live.ui.set

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.BuildConfig
import com.polaris.live.common.AppModule
import com.polaris.live.common.constant.CommonConst
import com.polaris.live.common.constant.ServerConfig
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.mvvm.base2.BaseVbActivity
import com.polaris.live.common.util.SystemUtils
import com.polaris.live.common.util.ToastGravity
import com.polaris.live.databinding.ActivityAboutBinding
import com.polaris.live.manager.AppConfigManager
import com.polaris.live.translation.R.string
import com.polaris.live.utils.route.RouterUtils
import com.polaris.live.viewmodel.SetViewModel

/**
 * 关于
 *
 * @author Created by 长空 on 2023/11/35/004 11:10
 */
class AboutActivity : BaseVbActivity<SetViewModel, ActivityAboutBinding>() {

    @SuppressLint("SetTextI18n")
    override fun initView(savedInstanceState: Bundle?) {
        mBinding.tvEmail.text = StringUtils.getString(
            string.my_email,
            AppConfigManager.getConfig(CommonConst.Configs.email) ?: ""
        )
        initListener()

        if (ServerConfig.isDebug() || !ServerConfig.isProdServer()) {
            mBinding.tvDebug.visibility = View.VISIBLE
            mBinding.tvDebug.text =
                "BuildDate ${BuildConfig.BUILD_DATE}\nFlavor ${BuildConfig.FLAVOR}\nServer ${BuildConfig.SERVER_ENV}"
        } else {
            mBinding.tvDebug.visibility = View.VISIBLE
            mBinding.tvDebug.text =
                "${StringUtils.getString(string.setting_version)}：${AppModule.getVersionName()}"
        }
    }

    private fun initListener() {
        mBinding.csFacebook.setOnSingleClickListener {
            AppConfigManager.getConfig(CommonConst.Configs.facebook)?.let {
                SystemUtils.launchFacebook(it)
            }
        }
        mBinding.csEmail.setOnSingleClickListener {
            SystemUtils.copyToClipboard(this, "${resources.getText(string.recharge_email)}")
            ToastGravity.showGravity(StringUtils.getString(string.copy_success))
        }
        mBinding.csService.setOnSingleClickListener {
            RouterUtils.routerGoto(CommonConst.Agreement.TERMS_OF_SERVICE)
        }
        mBinding.csPolicy.setOnSingleClickListener {
            RouterUtils.routerGoto(CommonConst.Agreement.PRIVACY_POLICY)
        }
        mBinding.csChildSafety.setOnSingleClickListener {
            RouterUtils.routerGoto(CommonConst.Agreement.CHILD_SAFETY)
        }
    }

}